# coding: utf8
#########################################
# Automatically add a new auth_group role and description
#########################################
#
# Author         : Christopher Steel
# Contact Info   : Christopher.Steel@VoiceOfAccess.org
# Organization   : Voice of Access
# Date           : 2010-06-06
# License        : GNU General Public License v3
# Description:
#
# Automatically add a new group and the auth_group table.
#
# You may want to delete the file once this task has been completed to speed up application execution.
#
###
# To do
###
#
# genericize functionality as a function that can be called (get DRY!)
# this should be done in the site administration app I think.
#
# Notes:
###
#
# Order of execution
#
# Naming the file so that it gets executed after the file containing the
# auth_table definition is executed (db.py) is the way to go!
#
# naming convention suggestions
#
# File name example:
#
#       models/init_0_uc_admin_add_auth_group_site_administration.py
#
# uc (universal cake) syntax break down:
#
#       init                type of action (comes after 'db', see order of execution notes as well)
#       #                   used to place the file in the order of execution we want. 
#       uc_admin            application (uc = universal cake, please change if you are not uc compliant)
#       add                 action
#       auth_group          action target
#       site_administration group to add
#       .py                 file extension
#
###
# References:
###
#
# http://127.0.0.1:8000/examples/default/tools#authentication
#

target_value_1 = 'site_administration'
target_value_2 = 'Users who are members of the group, %s, have full CRUD (create, read , update and delete) to all data that this application has full CRUD access to.' % (target_value_1)

target_value_1_found='None'

rows=db(db.auth_group.role == target_value_1).select(db.auth_group.ALL)
for row in rows:
    target_value_1_found = row.role
if target_value_1_found == 'None':
    new_group_id = db.auth_group.insert(role=target_value_1,description=target_value_2)
else:
    new_group_id = target_value_1_found[0]
